package utpl.edu.ec;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author Santiago
 */
public class PeriodosActivity extends Activity {

    private static final String NAMESPACE = "http://utpl.edu.ec/contract/syllabus/es/PeriodoAcademicoService/v1/";
    private static String URL = "http://172.16.56.20:8080/PeriodoAcademicoES.svc?wsdl";
    private static final String METHOD_NAME = "consultarTodos";
    private static final String SOAP_ACTION = "http://utpl.edu.ec/contract/syllabus/es/PeriodoAcademicoService/v1/IPeriodoAcademicoES/consultarTodos";
    TextView tv;
    Bundle extras;
    ListView lv;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        // ToDo add your GUI initialization code here 
        setContentView(R.layout.periodos);
        extras = getIntent().getExtras();

        tv = (TextView) findViewById(R.id.txtCedula);
        tv.setText(extras.getString("cedula"));
        lv = (ListView) findViewById(R.id.lstPeriodos);
        ArrayList<String> strPeriodos = new ArrayList<String>();

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(request);
        HttpTransportSE htrans = new HttpTransportSE(URL);

        try {
            htrans.call(SOAP_ACTION, soapEnvelope);
            SoapObject result = (SoapObject) soapEnvelope.bodyIn;
            for (int i = result.getPropertyCount()-1; i >0; i--) {
                SoapObject soapobj = (SoapObject) result.getProperty(i);
                strPeriodos.add(soapobj.getProperty("nombre").toString());
            }
            lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strPeriodos));


        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                
            }
        });

    }
}
